You can call GetAppParms to determine your application's name and the reference number of its resource file. When your application starts up, you can call CountAppFiles to determine whether the user selected any documents to open or print. If so, you can call GetAppFiles and ClrAppFiles to process the information passed to your application by the Finder.
If your application supports high-level events, you receive this information from the Finder in an Open Documents or Print Documents event.
You can use the GetAppParms procedure to get information about the current application and about files selected by the user for opening or printing.
PROCEDURE GetAppParms(VAR apName: Str255; VAR apRefNum: Integer;
VAR apParam: Handle);
The GetAppParms procedure returns information about the current application. You can call GetAppParms at application launch time to determine which files, if any, the user has selected in the Finder for opening or printing. You can call GetAppParms at any time to determine the current application's name and the reference number of the application's resource fork.
The GetAppParms procedure returns the application's name in the apName parameter and the reference number of its resource fork in the apRefNum parameter. A handle to the Finder information is returned in apParam . This information consists of a word that encodes the message or action to be performed, a word that indicates how many files to process, and a list of Finder information about each such file. The Finder information has the structure of an AppFile record, except that the filename occupies only as many bytes as are required to hold the name (padded to an even number of bytes, if necessary). In general, it is easier to use the GetAppFiles procedure to access the Finder information.
If you simply want to determine the application's resource file reference number, you can call the Resource Manager function CurResFile when your application starts up.
If you need more extensive information about the application than GetAppParms provides, you can use the Process Manager function GetCurrentProcess .
You can use the CountAppFiles procedure to determine how many documents (if any) the user has selected at application launch time for opening or printing.
PROCEDURE CountAppFiles (VAR message: Integer;
VAR count: Integer);
The CountAppFiles procedure deciphers the Finder information passed to your application and returns information about the files that were selected when your application was started up. On exit, the count parameter contains the number of selected files, and the message parameter contains an integer that indicates whether the files are to be opened or printed. The message parameter contains one of these constants:
CONST
appOpen = 0; {open the document(s)}
appPrint = 1; {print the document(s)}
You can use the GetAppFiles procedure to retrieve information about each file selected at application startup for opening or printing.
PROCEDURE GetAppFiles (index: Integer; VAR theFile: AppFile);
The GetAppFiles procedure returns information about a file that was selected when your application was started up (as listed in the Finder information). The index parameter indicates the file for which information should be returned; it must be between 1 and the number returned by CountAppFiles , inclusive.
You can use the ClrAppFiles procedure to notify the Finder that you have processed the information about a file selected for opening or printing at application startup.
PROCEDURE ClrAppFiles (index: Integer);
The ClrAppFiles procedure changes the Finder information passed to your application about the specified file so that the Finder knows you've processed the file. The index parameter must be between 1 and the number returned by CountAppFiles , inclusive. You should call ClrAppFiles for every document your application opens or prints, so that the information returned by CountAppFiles and GetAppFiles is always correct. The ClrAppFiles procedure sets the file type in the Finder information to 0.